package main

import (
	"os"
	"wechat-push/config"
	"wechat-push/internal"
	"wechat-push/internal/crontab"
	"wechat-push/pkg/logger"
	"wechat-push/pkg/signal"
)

func main() {
	// 获取启动或命令行参数
	args := os.Args

	// config 初始化
	isLoaded := config.Init()
	if !isLoaded {
		logger.Log.Error("load config failed, app exited...")
		return
	}
	// 可用于测试及手动推送
	if len(args) == 2 && (args[1] == "-t" || args[1] == "-test" || args[1] == "--test") {
		internal.SendMorning()
		return
	}
	// 是否开启定时任务
	if config.Cfg.Cron.On {
		err := crontab.Schedule()
		if err != nil {
			logger.Log.Error("crontab.Schedule err : ", err)
			return
		}
	}
	logger.Log.Info("app start complete...")
	// 等待退出信号
	signal.WaitForSignals()
	logger.Log.Info("app exit ！")
}
